import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:fantuike_app/api/Api.dart' show Api;

class NoticeDetail extends StatefulWidget {
  int noticeId;

  NoticeDetail({Key key, @required this.noticeId}) : super(key: key);

  @override
  _NoticeDetailState createState() => _NoticeDetailState();
}

class _NoticeDetailState extends State<NoticeDetail> {
  PreferredSize buildAppBarWidget() {
    return PreferredSize(
        child: AppBar(
          leading: IconButton(
              icon: Icon(
                Icons.chevron_left,
                size: 30.0,
                color: Color(0xffffffff),
              ),
              onPressed: () {
                Navigator.pop(context);
              }),
          backgroundColor: Color(0xfff26966),
          title: Text(
            title,
            style: TextStyle(
                color: Color(
                  0xffffffff,
                ),
                fontSize: 16.0),
          ),
          centerTitle: true,
          elevation: 0.0,
        ),
        preferredSize:
            Size.fromHeight(MediaQuery.of(context).size.height * 0.065));
  }

  String title = "";

  String content = "";

  String createDate = "";

  @override
  void initState() {
    super.initState();
    getNoticeDetail();
  }

  void getNoticeDetail() {
    _getNoticeDetail().then((data) {
      setState(() {
        title = data['extend']['message']['title'];
        content = data['extend']['message']['content'];
        createDate = data['extend']['message']['createDate'];
      });
    });
  }

  Future _getNoticeDetail() async {
    try {
      Response response = await Dio().get(Api.getSysNoticeDetail,
          queryParameters: {"id": widget.noticeId});
      return response.data;
    } catch (e) {
      print(e);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: buildAppBarWidget(),
      body: SingleChildScrollView(
        child: Container(
            margin: const EdgeInsets.only(
                top: 10.0, left: 5.0, right: 5.0, bottom: 50.0),
            padding: const EdgeInsets.all(5.0),
            alignment: Alignment.topCenter,
            child: new Card(
                elevation: 20.0,
                //设置阴影
                shape: const RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(14.0))),
                //设置圆角
                child: Column(
                  children: <Widget>[
                    Container(
                      child: Text(
                        title,
                        style: TextStyle(
                            fontSize: 18.0, fontWeight: FontWeight.w500),
                      ),
                      margin: const EdgeInsets.all(10.0),
                    ),
                    Container(
                      padding: const EdgeInsets.only(
                          left: 10.0, right: 10.0, top: 20.0),
                      child: Text(
                        content,
                        style: TextStyle(fontSize: 16.0),
                      ),
                    ),
                    Container(
                      margin: const EdgeInsets.only(
                          bottom: 5.0, right: 10.0, top: 20.0),
                      alignment: Alignment.bottomRight,
                      child: Text(createDate),
                    )
                  ],
                ))),
      ),
    );
  }
}
